#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include <sys/wait.h>

char *const addenv[]=
{
  (char *const)"MYVAL=123456789",
  (char *const)"MYVAL1=123456789",
  (char *const)"MYVAL2=123456789",NULL
};

int main()
{
  printf("程序已经运行\n");
  
  if(fork()==0)
  {
    printf("I am Child, My PID is:%d \n",getpid());
    sleep(1); 
  
    //===模拟bash 指令传入===
    char*const argv[]={
      (char*const)"other",
      (char*const)"-a",
      (char*const)"-b",
      (char*const)"-c",
      (char*const)"-d",NULL
    };


    //execvpe("./other",argv,env);//全新的
    //
   // execvp("./other",argv);//追加方式传入环境变量，虽然没有传入env,但是系统会自己传
    //===环境变量表追加方式=======
    for(int i=0;addenv[i];i++){
        putenv(addenv[i]);
    }
    extern char** environ;
    execvpe("./other",argv,environ);//进程替换且追加环境变量
    //==============================
    exit(1);//结束子进程
  }

  waitpid(-1,NULL,0);//等待子进程结束
  printf("运行完毕\n");
  return 0;
}
